package org.example.visibility;

import lombok.extern.slf4j.Slf4j;
import org.example.utils.Sleeper;

/**
 * @author zhengdp
 * @Description 可见性测试
 * @Date 2022/11/10 21:22
 * @Created by zhengdp
 */
@Slf4j(topic = "c.VisibilityTest")
public class VisibilityTest {

    static boolean run = true;

    final static Object LOCK = new Object();

    public static void main(String[] args) {
        Thread t = new Thread(()-> {
            while (true){
                // ....
                synchronized (LOCK){
                    if(!run){
                        break;
                    }
                }
            }
        },"t1");
        t.start();

        Sleeper.sleep(1000);
        log.info("停止t");
        synchronized (LOCK){
            run = false;
        }
    }
}
